﻿using AutoMapper;
using FarmSmartSleep.Common.Domain;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.Commands.EnterpriseCommands
{
    public class IndustryLabelsTypeHandler: IRequestHandler<IndustryLabelsTypeCommand, Result>
    {
        public IBaseRepository<IndustryLabels> IndustryLabelsRepository;//一级
        public IBaseRepository<Industry> IndustryRepository;//二级
        public IMapper mapper;

        public IndustryLabelsTypeHandler(IBaseRepository<IndustryLabels> industryLabelsRepository, IBaseRepository<Industry> industryRepository, IMapper mapper)
        {
            IndustryLabelsRepository = industryLabelsRepository;
            IndustryRepository = industryRepository;
            this.mapper = mapper;
        }

        //一级下拉框
        public Task<Result> Handle(IndustryLabelsTypeCommand request, CancellationToken cancellationToken)
        {
            Result result = new Result();
            result.Code = 1;
            result.Messege = "成功";
            var res = IndustryLabelsRepository.GetAll().ToList();
            List<IndustryLabelsTypeListCommand> lists=new List<IndustryLabelsTypeListCommand>();
            foreach (var item in res)
            {
                var sf=mapper.Map<IndustryLabelsTypeListCommand>(item);
                lists.Add(sf);
            }
            result.Data = lists;
            return Task.FromResult(result);
        }
    }
}
